#pragma once

#include<iostream>
#include<pthread.h>

class Task{
  private:
    int x;
    int y;
    char op;
  public:
    Task()   //必须有无参构造，以便线程池可有变量提取
    {}
    Task(int _x,int _y,char _op)
      :x(_x),y(_y),op(_op)
    {}
    void operator()()
    {
      run();
    }
    void run()
    {
      int z=-1;
      switch(op)
      {
        case '+':
          z=x+y;
          break;
        case '-':
          z=x-y;
          break;
        case '*':
          z=x*y;
          break;
        case '/':
          if(y!=0)
            z=x/y;
          else
            std::cout<<"Waring: div zero"<<std::endl;
          break;
        case '%':
          if(y!=0)
            z=x%y;
          else
            std::cout<<"Waring: div zero"<<std::endl;
          break;
        default:
          std::cout<<"unkown operator!"<<std::endl;
      }
      if(z!=-1)
        std::cout<<"thread"<<"["<<pthread_self()<<"] handler task done: "<<x<<op<<y<<"="<<z<<std::endl;
    }
    ~Task()
    {}
};
